package com.hongsheng.service.impl;

/*
@Author：郭振文
@Package：com.hongsheng.service.impl
@File：UserServiceImpl
@Date：2023/8/10 22:58
*/

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hongsheng.mapper.UserMapper;
import com.hongsheng.pojo.UR;
import com.hongsheng.pojo.User;
import com.hongsheng.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
   private UserMapper userMapper;

    @Override
    public Boolean insertUser(User user) {
        int i = userMapper.insert(user);
        return i>0;
    }

    @Override
    public Boolean deleteUser(Integer id) {
        int i = userMapper.deleteById(id);
        return i>0;
    }

    @Override
    public Boolean updateUser(User user) {
        return userMapper.updateUser(user);
    }

    @Override
    public PageInfo<User> selectUser(Integer currentPage, Integer pageSize, User user) {
        PageHelper.startPage(currentPage,pageSize);
        List<User> userList = userMapper.selectUser("%"+user.getName()+"%", user.getSex(), "%"+user.getAddress()+"%", user.getStatus());
        return new PageInfo<User>(userList);
    }



    @Override
    public User selectUserById(Integer id) {
        User user = userMapper.selectUserById(id);
        return user;
    }

    @Override
    public Boolean insertUserRole(UR ur) {
        return userMapper.insertUserRole(ur);
    }

    @Override
    public Boolean deleteUserRole(UR ur) {
        return userMapper.deleteUserRole(ur);
    }

    @Override
    public Boolean selectUsername(User user) {
        User user1 = userMapper.selectUserById(user.getId());
        String s1 = user1.getUsername();
        String s = userMapper.selectUsername(user.getUsername());
        System.out.println(s1);
        System.out.println(s);
        if (s==null || s.isEmpty()) {
           return true;
        }else if (s.equals(s1)){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean selectUsername1(User user) {
        String s = userMapper.selectUsername(user.getUsername());
        if (s==null || s.isEmpty()) {
            return true;
        }else {
            return false;
        }
    }

    @Override
    public Boolean selectUR(UR ur) {
        List<UR> urList = userMapper.selectUR(ur);
        if (urList==null || urList.isEmpty()){
            return true;
        }else {
            return false;
        }
    }


}
